package myjava.i_collection;

import java.util.HashMap;

/**
 * @Auther: cty
 * @Date: 2019/11/15 下午10:26
 * @Description:
 * @version: 1.0
 */
public class K_MyHashSet {
    HashMap map;
    private static final Object PRESENT = new Object();

    public K_MyHashSet(){
        map = new HashMap();
    }

    public int size(){
        return map.size();
    }

    public void add(Object o){
        map.put(o,PRESENT);
    }

    @Override
    public String toString() {

        StringBuffer sb = new StringBuffer("[");
        for(Object key:map.keySet()){
            sb.append(key+",");
        }
        sb.setCharAt(sb.length()-1,']');
        return sb.toString();
    }

    public static void main(String[] args) {
        K_MyHashSet set = new K_MyHashSet();
        set.add("aaa");
        set.add("bbb");
        set.add("ccc");
        System.out.println(set);
    }
}
